﻿using HealthcareSystem.API.Write.Application.Command.MetricsCommands;
using HealthcareSystem.Domain.BasicSettings.Metrics;
using MediatR;
using Microsoft.AspNetCore.Server.HttpSys;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.MetricsCommands
{
    /// <summary>
    /// 指标分类新增处理命令
    /// </summary>
    public class MetricsClassCommandHandler : IRequestHandler<MetricsClassCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<MetricsClass> metRep;

        public MetricsClassCommandHandler(IBaseRepository<MetricsClass> metRep)
        {
            this.metRep = metRep;
        }

        public async Task<ApiResult<int>> Handle(MetricsClassCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.Success;
            result.Message=ResultCode.添加成功.ToString();
            
            MetricsClass met=new MetricsClass();
            met.MetricsClassName=request.MetricsClassName;
            await metRep.AddAsync(met);
            return await Task.FromResult(result);


        }
    }
}
